package com.lzy.health.controller;

import com.lzy.health.common.MessageConst;
import com.lzy.health.entity.Result;
import com.lzy.health.pojo.User;
import com.lzy.health.service.UserService;
import com.lzy.health.vo.LoginParam;
import jdk.nashorn.internal.ir.annotations.Reference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {
    @Reference
    private UserService userService;
    @PostMapping("login")
    public Result Login(HttpServletRequest request, @RequestBody LoginParam param){
       log.info("[登录]data:{}",param);
       User user= userService.findByUserName(param.getUsername());
       if(user==null||!user.getPassword().equals(param.getPassword())){
           log.info("[登录]失败，user:{}",param.getUsername());
           return new Result(false, MessageConst.LOGIN_FAIL);
       }
       log.info("[登录]成功，user:{}",user.getUsername());
        return new Result(true, MessageConst.LOGIN_SUCCESS);
    }

}
